﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IDAL;

namespace KPIS.GERP.GFMS.DAL
{
    public class D_HRM_MP_Classes : IDAL_HRM_MP_Classes
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        ConvertNullable cn = new ConvertNullable();
        

        public D_HRM_MP_Classes()
        {

        }

        public DataTable GetList(bool bOld, bool bNew)
        {
            string strSQL;
            DataTable dtb = null;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(3);

                dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);
                dbManager.AddParameters(1, "@cancel_status", SystemInfo._CancelRecordStatus);
                dbManager.AddParameters(2, "@active_status", SystemInfo._ActiveRecordStatus);

                strSQL = "SELECT class_seq, class_name"
                    + " FROM hrm_mp_classes"
                    + " WHERE record_status not like @delete_status"
                    + (bOld ? " AND record_status = @cancel_status" : "")
                    + (bNew ? " AND record_status = @active_status" : "");
                

                dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return dtb;
        }

        public DataTable GetList(Nullable<int> pos_type_seq)
        {
            string strSQL;
            DataTable dtb = null;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);

                dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);
                dbManager.AddParameters(1, "@pos_type_seq", pos_type_seq);

                strSQL = "SELECT class_seq, class_name"
                    + " FROM hrm_mp_classes"
                    + " WHERE record_status not like @delete_status"
                    + (pos_type_seq != null ? " and pos_type_seq = @pos_type_seq" : "");
                

                dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return dtb;
        }

        public DataRow GetInfo(int seq)
        {
            string strSQL;
            DataRow dr = null;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@seq", seq);

                strSQL = "SELECT class_seq, class_no, class_name, class_name_short"
                    + ", class_eng, class_eng_short, pos_type_seq, emp_type_seq"
                    + " FROM hrm_mp_classes"
                    + " WHERE class_seq = @seq";
                

                dr = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows[0];
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return dr;
        }
    }
}
